package com.sjhang.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sjhang.entity.TbCollect;
import com.sjhang.mapper.TbCollectMapper;
import com.sjhang.service.TbCollectService;
import com.sjhang.utils.ListParamVo;
import com.sjhang.utils.ResultResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户收藏文章表  服务实现类
 *
 */
@Service
public class TbCollectServiceImpl extends ServiceImpl<TbCollectMapper, TbCollect> implements TbCollectService {

    @Resource
    private TbCollectMapper tbCollectMapper;


    /***
     * @description 查询某个用户的收藏，根据个人id
     * @params [listParamVo]
     */
    @Override
    public ResultResponse selectCollect(ListParamVo listParamVo) {
        IPage<TbCollect> tbCollectIPage = tbCollectMapper.selectCollectPage(
                new Page<TbCollect>(listParamVo.getCurrent(), listParamVo.getSize()),
                 listParamVo.getParamMap().get("issuedId")
        );
        return ResultResponse.SUCCESS(tbCollectIPage);
    }

    /**
     * @description 添加文章到我的收藏
     * @params [listParamVo]
     */
    @Override
    public ResultResponse insertCollect(TbCollect listParamVo) {
        tbCollectMapper.insert(listParamVo);
        return ResultResponse.SUCCESS();
    }

    /***
     * @description 从我的收藏里删除某一个
     * @params [listParamVo]
     */
    @Override
    public ResultResponse deleteCollect(Long listParamVo) {
        tbCollectMapper.deleteById(listParamVo);
        return ResultResponse.SUCCESS();
    }

    /***
     * @description 修改我的收藏
     * @params [listParamVo]
     */
    @Override
    public ResultResponse updateCollect(TbCollect listParamVo) {

        return null;
    }
}
